import {get,post} from '../../utils/request'
const state={
  //用来保存查询出来的栏目信息
  baseUsers:[],
  total:0
}

const actions={
  //查询所有栏目信息
  findAllUser(context,list){
    for (var propName in list) { 
      if (list[propName] === null || list[propName] === undefined || list[propName]==="") {
        delete list[propName];
      }
    }
    //异步操作
    get('/baseUser/pageQuery',list).then(res=>{
      let response=res.data.list
      context.commit('setBaseUser',response)
      let total=res.data.total
      context.commit('setTotal',total)
    })
  },
  //添加员工
  addUser(context,from){
    let response=post('/baseUser/addUserWidthRole',from)
    return response
  },
  //删除用户
  delete(context,id){
     let response=get('/baseUser/deleteById',id)
     return response
  },
  //更新用户
  saveUser(context,from){
    let response=post('/baseUser/saveOrUpdate',from)
    return response
  }

}

const mutations={
  //修改state中的值
  setBaseUser(state,response){
    state.baseUsers=response
  },
  setTotal(state,total){
    state.total=total
  }
}

export default{
  namespaced:true,
  state,
  actions,
  mutations
}